package com.mao.spring.cloud.controller;

import com.mao.spring.cloud.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author: Administrator
 * @description:
 * @cteate 2021-06-15-16:19
 */
@RestController
public class HumanResourceController {

    @Autowired
    @LoadBalanced
    private RestTemplate restTemplate;

    @RequestMapping("/consumer/get/employee")
    public Employee getEmployeeRemote(){

        // 远程方法调用:主机地址
        //String host = "http://localhost:1000";
        //使用微服务名称,从eureka中获取到对应的主机地址
        String host = "http://mao-provider";
        // 远程方法调用:方法的具体url地址
        String url = "/provider/get/employee/remote";

        return restTemplate.getForObject(host + url,Employee.class);
    }
}
